package com.goodfather.textbook.youdao.pad.bean;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.List;

/**
 * 唯一书本标识为 bookId+publishingId
 * tv端绘本只需用到lesson数组,按照beginPage排序,取出videoUrl
 * tv端教材音频对应lesson,sentence对应的点读框
 */

public class BookDetail implements Parcelable {

    public String bookId;
    public int bookTypeId;
    public String coverImageUrl;
    public int freeLessons;//免费的课程（不可能是0）
    public int freePages;
    public String publishingId;
    public String subjectId;
    public int productionId;
    public int productionTypeId;
    public String bookName;
    public String classifyName;
    public String cornerMarkUrl;
    public int classifyId;
    public String videoUrl;
    public boolean multipleLanguage;//双语
    public List<Lessons> lessons;
    public List<Pages> pages;
    public long time = System.currentTimeMillis();//插入数据时间
    public int leftIndex;
    public int rightIndex;
    public int curLessonIndex;//当前阅读课程
    public int isReadSentence;//0 没有 1 有
    public boolean canPlay;
    public Recover recover;

    public String thirdPartyAlbumId;
    public String thirdPartyUnitId;
    public String programType;
    public int duration;

//    public Production production;
//
//   public static class Production {
//        int id;
//        String name;
//        boolean isFree;
//
//       public int getId() {
//           return id;
//       }
//
//       public void setId(int id) {
//           this.id = id;
//       }
//
//       public String getName() {
//           return name;
//       }
//
//       public void setName(String name) {
//           this.name = name;
//       }
//
//       public boolean isFree() {
//           return isFree;
//       }
//
//       public void setFree(boolean free) {
//           isFree = free;
//       }
//   }

    public BookDetail(){}

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.bookId);
        dest.writeInt(this.bookTypeId);
        dest.writeString(this.coverImageUrl);
        dest.writeInt(this.freeLessons);
        dest.writeInt(this.freePages);
        dest.writeString(this.publishingId);
        dest.writeString(this.subjectId);
        dest.writeInt(this.productionId);
        dest.writeInt(this.productionTypeId);
        dest.writeString(this.bookName);
        dest.writeString(this.classifyName);
        dest.writeString(this.cornerMarkUrl);
        dest.writeInt(this.classifyId);
        dest.writeString(this.videoUrl);
        dest.writeByte(this.multipleLanguage ? (byte) 1 : (byte) 0);
        dest.writeTypedList(this.lessons);
        dest.writeTypedList(this.pages);
        dest.writeLong(this.time);
        dest.writeInt(this.leftIndex);
        dest.writeInt(this.rightIndex);
        dest.writeInt(this.curLessonIndex);
        dest.writeInt(this.isReadSentence);
        dest.writeByte(this.canPlay ? (byte) 1 : (byte) 0);
        dest.writeParcelable(this.recover, flags);
        dest.writeString(this.thirdPartyAlbumId);
        dest.writeString(this.thirdPartyUnitId);
        dest.writeString(this.programType);
        dest.writeInt(this.duration);
    }

    protected BookDetail(Parcel in) {
        this.bookId = in.readString();
        this.bookTypeId = in.readInt();
        this.coverImageUrl = in.readString();
        this.freeLessons = in.readInt();
        this.freePages = in.readInt();
        this.publishingId = in.readString();
        this.subjectId = in.readString();
        this.productionId = in.readInt();
        this.productionTypeId = in.readInt();
        this.bookName = in.readString();
        this.classifyName = in.readString();
        this.cornerMarkUrl = in.readString();
        this.classifyId = in.readInt();
        this.videoUrl = in.readString();
        this.multipleLanguage = in.readByte() != 0;
        this.lessons = in.createTypedArrayList(Lessons.CREATOR);
        this.pages = in.createTypedArrayList(Pages.CREATOR);
        this.time = in.readLong();
        this.leftIndex = in.readInt();
        this.rightIndex = in.readInt();
        this.curLessonIndex = in.readInt();
        this.isReadSentence = in.readInt();
        this.canPlay = in.readByte() != 0;
        this.recover = in.readParcelable(Recover.class.getClassLoader());
        this.thirdPartyAlbumId = in.readString();
        this.thirdPartyUnitId = in.readString();
        this.programType = in.readString();
        this.duration = in.readInt();
    }

    public static final Creator<BookDetail> CREATOR = new Creator<BookDetail>() {
        @Override
        public BookDetail createFromParcel(Parcel source) {
            return new BookDetail(source);
        }

        @Override
        public BookDetail[] newArray(int size) {
            return new BookDetail[size];
        }
    };
}
